package com.ogawa.project6602.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.text.InputFilter
import android.view.View
import android.view.Window
import android.widget.EditText
import android.widget.TextView
import com.ogawa.project6602.R

class DiyNameDialog(context: Context) : Dialog(context) {
    private var tvSave: TextView
    private var etInput: EditText

    init {
        window?.requestFeature(Window.FEATURE_NO_TITLE)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setContentView(R.layout.dialog_suantong_ready)
        tvSave = findViewById(R.id.saveBt)
        etInput = findViewById(R.id.inputEt)
        etInput.filters = arrayOf(InputFilter.LengthFilter(10))
        findViewById<TextView>(R.id.cancelButton).setOnClickListener { dismiss() }
    }

    fun setOnSaveClickListener(listener: View.OnClickListener) {
        tvSave.setOnClickListener(listener)
    }

    fun getInputContent(): String {
        return etInput.text.toString()
    }

    fun show(diyName: String? = null) {
        if (diyName != null) {
            etInput.setText(diyName)
            etInput.setSelection(diyName.length)
        }
        show()
    }
}